Passed
Pull Request — master (#47)
by
unknown
05:23
created

popover.js ➔ _interopDefaultLegacy   B

Complexity

Conditions 7

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 1
dl 0
loc 1
rs 8
c 0
b 0
f 0
1
/*!
2
  * Bootstrap popover.js v4.6.0 (https://getbootstrap.com/)
3
  * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
4
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
5
  */
6
(function (global, factory) {
7
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery'), require('./tooltip.js')) :
8
  typeof define === 'function' && define.amd ? define(['jquery', './tooltip'], factory) :
0 ignored issues
show
Bug introduced by
The variable define seems to be never declared. If this is a global, consider adding a /** global: define */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
9
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Popover = factory(global.jQuery, global.Tooltip));
0 ignored issues
show
Bug introduced by
The variable globalThis seems to be never declared. If this is a global, consider adding a /** global: globalThis */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Best Practice introduced by
If you intend to check if the variable self is declared in the current environment, consider using typeof self === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
10
}(this, (function ($, Tooltip) { 'use strict';
11
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
14
  var $__default = /*#__PURE__*/_interopDefaultLegacy($);
15
  var Tooltip__default = /*#__PURE__*/_interopDefaultLegacy(Tooltip);
16
17
  function _defineProperties(target, props) {
18
    for (var i = 0; i < props.length; i++) {
19
      var descriptor = props[i];
20
      descriptor.enumerable = descriptor.enumerable || false;
21
      descriptor.configurable = true;
22
      if ("value" in descriptor) descriptor.writable = true;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
23
      Object.defineProperty(target, descriptor.key, descriptor);
24
    }
25
  }
26
27
  function _createClass(Constructor, protoProps, staticProps) {
28
    if (protoProps) _defineProperties(Constructor.prototype, protoProps);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
29
    if (staticProps) _defineProperties(Constructor, staticProps);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
30
    return Constructor;
31
  }
32
33
  function _extends() {
34
    _extends = Object.assign || function (target) {
0 ignored issues
show
Comprehensibility introduced by
It seems like you are trying to overwrite a function name here. _extends is already defined in line 33 as a function. While this will work, it can be very confusing.
Loading history...
35
      for (var i = 1; i < arguments.length; i++) {
36
        var source = arguments[i];
37
38
        for (var key in source) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
39
          if (Object.prototype.hasOwnProperty.call(source, key)) {
40
            target[key] = source[key];
41
          }
42
        }
43
      }
44
45
      return target;
46
    };
47
48
    return _extends.apply(this, arguments);
49
  }
50
51
  function _inheritsLoose(subClass, superClass) {
52
    subClass.prototype = Object.create(superClass.prototype);
53
    subClass.prototype.constructor = subClass;
54
    subClass.__proto__ = superClass;
55
  }
56
57
  /**
58
   * ------------------------------------------------------------------------
59
   * Constants
60
   * ------------------------------------------------------------------------
61
   */
62
63
  var NAME = 'popover';
64
  var VERSION = '4.6.0';
65
  var DATA_KEY = 'bs.popover';
66
  var EVENT_KEY = "." + DATA_KEY;
67
  var JQUERY_NO_CONFLICT = $__default['default'].fn[NAME];
68
  var CLASS_PREFIX = 'bs-popover';
69
  var BSCLS_PREFIX_REGEX = new RegExp("(^|\\s)" + CLASS_PREFIX + "\\S+", 'g');
70
71
  var Default = _extends({}, Tooltip__default['default'].Default, {
72
    placement: 'right',
73
    trigger: 'click',
74
    content: '',
75
    template: '<div class="popover" role="tooltip">' + '<div class="arrow"></div>' + '<h3 class="popover-header"></h3>' + '<div class="popover-body"></div></div>'
76
  });
77
78
  var DefaultType = _extends({}, Tooltip__default['default'].DefaultType, {
79
    content: '(string|element|function)'
80
  });
81
82
  var CLASS_NAME_FADE = 'fade';
83
  var CLASS_NAME_SHOW = 'show';
84
  var SELECTOR_TITLE = '.popover-header';
85
  var SELECTOR_CONTENT = '.popover-body';
86
  var Event = {
87
    HIDE: "hide" + EVENT_KEY,
88
    HIDDEN: "hidden" + EVENT_KEY,
89
    SHOW: "show" + EVENT_KEY,
90
    SHOWN: "shown" + EVENT_KEY,
91
    INSERTED: "inserted" + EVENT_KEY,
92
    CLICK: "click" + EVENT_KEY,
93
    FOCUSIN: "focusin" + EVENT_KEY,
94
    FOCUSOUT: "focusout" + EVENT_KEY,
95
    MOUSEENTER: "mouseenter" + EVENT_KEY,
96
    MOUSELEAVE: "mouseleave" + EVENT_KEY
97
  };
98
  /**
99
   * ------------------------------------------------------------------------
100
   * Class Definition
101
   * ------------------------------------------------------------------------
102
   */
103
104
  var Popover = /*#__PURE__*/function (_Tooltip) {
105
    _inheritsLoose(Popover, _Tooltip);
106
107
    function Popover() {
108
      return _Tooltip.apply(this, arguments) || this;
109
    }
110
111
    var _proto = Popover.prototype;
112
113
    // Overrides
114
    _proto.isWithContent = function isWithContent() {
115
      return this.getTitle() || this._getContent();
116
    };
117
118
    _proto.addAttachmentClass = function addAttachmentClass(attachment) {
119
      $__default['default'](this.getTipElement()).addClass(CLASS_PREFIX + "-" + attachment);
120
    };
121
122
    _proto.getTipElement = function getTipElement() {
123
      this.tip = this.tip || $__default['default'](this.config.template)[0];
124
      return this.tip;
125
    };
126
127
    _proto.setContent = function setContent() {
128
      var $tip = $__default['default'](this.getTipElement()); // We use append for html objects to maintain js events
129
130
      this.setElementContent($tip.find(SELECTOR_TITLE), this.getTitle());
131
132
      var content = this._getContent();
133
134
      if (typeof content === 'function') {
135
        content = content.call(this.element);
136
      }
137
138
      this.setElementContent($tip.find(SELECTOR_CONTENT), content);
139
      $tip.removeClass(CLASS_NAME_FADE + " " + CLASS_NAME_SHOW);
140
    } // Private
141
    ;
142
143
    _proto._getContent = function _getContent() {
144
      return this.element.getAttribute('data-content') || this.config.content;
145
    };
146
147
    _proto._cleanTipClass = function _cleanTipClass() {
148
      var $tip = $__default['default'](this.getTipElement());
149
      var tabClass = $tip.attr('class').match(BSCLS_PREFIX_REGEX);
150
151
      if (tabClass !== null && tabClass.length > 0) {
152
        $tip.removeClass(tabClass.join(''));
153
      }
154
    } // Static
155
    ;
156
157
    Popover._jQueryInterface = function _jQueryInterface(config) {
158
      return this.each(function () {
159
        var data = $__default['default'](this).data(DATA_KEY);
160
161
        var _config = typeof config === 'object' ? config : null;
162
163
        if (!data && /dispose|hide/.test(config)) {
164
          return;
165
        }
166
167
        if (!data) {
168
          data = new Popover(this, _config);
169
          $__default['default'](this).data(DATA_KEY, data);
170
        }
171
172
        if (typeof config === 'string') {
173
          if (typeof data[config] === 'undefined') {
174
            throw new TypeError("No method named \"" + config + "\"");
175
          }
176
177
          data[config]();
178
        }
179
      });
180
    };
181
182
    _createClass(Popover, null, [{
183
      key: "VERSION",
184
      // Getters
185
      get: function get() {
186
        return VERSION;
187
      }
188
    }, {
189
      key: "Default",
190
      get: function get() {
191
        return Default;
192
      }
193
    }, {
194
      key: "NAME",
195
      get: function get() {
196
        return NAME;
197
      }
198
    }, {
199
      key: "DATA_KEY",
200
      get: function get() {
201
        return DATA_KEY;
202
      }
203
    }, {
204
      key: "Event",
205
      get: function get() {
206
        return Event;
207
      }
208
    }, {
209
      key: "EVENT_KEY",
210
      get: function get() {
211
        return EVENT_KEY;
212
      }
213
    }, {
214
      key: "DefaultType",
215
      get: function get() {
216
        return DefaultType;
217
      }
218
    }]);
219
220
    return Popover;
221
  }(Tooltip__default['default']);
222
  /**
223
   * ------------------------------------------------------------------------
224
   * jQuery
225
   * ------------------------------------------------------------------------
226
   */
227
228
229
  $__default['default'].fn[NAME] = Popover._jQueryInterface;
230
  $__default['default'].fn[NAME].Constructor = Popover;
231
232
  $__default['default'].fn[NAME].noConflict = function () {
233
    $__default['default'].fn[NAME] = JQUERY_NO_CONFLICT;
234
    return Popover._jQueryInterface;
235
  };
236
237
  return Popover;
238
239
})));
240
//# sourceMappingURL=popover.js.map
241